package com.bra.utils;

import com.bra.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

/**
 * @Title: 适用于所有的activity界面弹窗
 * @Package com.gxyk.wifi.dialog
 * @author CaoYi
 * @date 2015年5月27日 上午11:12:19
 */
public class DialogAct extends Dialog implements
		android.view.View.OnClickListener {

	private int layoutRes;// 布局文件
	private Context context;
	private String info,submit,cancle;
   private MyDialogListener listener;
    
    public interface MyDialogListener{   
        public void onClickListener(View view);   
    }   
	public DialogAct(Context context) {
		super(context);
		this.context = context;
	}

	/**
	 * 自定义布局的构造方法
	 * 
	 * @param context
	 * @param resLayout
	 */
	public DialogAct(Context context, int resLayout,String info,String submit,String cancle,MyDialogListener listener) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.context = context;
		this.layoutRes = resLayout;
		this.info=info;
		this.submit=submit;
		this.cancle=cancle;
		this.listener=listener;
	}

	/**
	 * 自定义主题及布局的构造方法
	 * 
	 * @param context
	 * @param theme
	 * @param resLayout
	 */
	public DialogAct(Context context, int theme, int resLayout) {
		super(context, theme);
		this.context = context;
		this.layoutRes = resLayout;
	}

	/** 确定按钮 **/
	private TextView confirmBtn;
	/** 取消按钮 **/
	private TextView cancelBtn;
	private TextView show_tv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View view = LayoutInflater.from(context).inflate(layoutRes, null);
		this.setContentView(view);
		confirmBtn = (TextView) view.findViewById(R.id.submit_tv);
		cancelBtn = (TextView) view.findViewById(R.id.cancel_tv);
		show_tv=(TextView) view.findViewById(R.id.show_tv);
		show_tv.setText(info);
		confirmBtn.setText(submit);
		cancelBtn.setText(cancle);
		confirmBtn.setOnClickListener(this);
		cancelBtn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.cancel_tv:		
			DialogAct.this.dismiss();			
			break;
		case R.id.submit_tv:// 
			listener.onClickListener(v);
			DialogAct.this.dismiss();
			break;
		default:
			break;
		}
	}

}